<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>云信账单上传失败管理</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 60px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
    </style>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>


<script type="text/javascript">
	var grid = null;
	$(function () {
	    initForm();
		initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
		//initEvent();
	});
	
	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}
	
	//查询按钮事件
	function searchBtn(){
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	}
	
	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
        var data = form.getData();
        return data;
	}
	
	//初始化列表
	function initGrid(){
		$("#ligergrid1").ligerGrid({
			url: '<%=path%>/mcr/mcrBillM/initUploadFilesManageList.do',
            method: 'get',
            columns: [
                {display: '账单ID', name: 'billId', minWidth: 100, align: 'center', },
                {display: '客户ID', name: 'cstId', minWidth: 100, align: 'center',
                    render: function (rowdata, rowindex, value, column) {
                        if(StringUtils.isEmpty(value)){
                            value = "";
                        }
                        var h = '';
                        h='<a href="javascript:showDetail(';
                        h+="'"+value+"'";
                        h+=')">'+value+'</a>'
                        return h;
                    } },
                {display: '客户名称', name: 'cstNm', minWidth: 100, align: 'center', },
                {display: '证件号', name: 'certNo', minWidth: 100, align: 'center', },
                {display: '机构ID', name: 'fundRasInsId', minWidth: 100, align: 'center', },
                {display: '机构名称', name: 'fundRasInsNm', minWidth: 100, align: 'center', },
               /*  {display: '发送状态', name: 'status', minWidth: 100, align: 'center', }, */
                getGridOperColumnContent()
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false
        });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	}
	
	
  	//Grid操作列
    function getGridOperColumnContent(){
  		var currentUserId = $("#currentUserId").val();
    	var data = {
                display: '操作',
                isSort: false,
                width: 280,
                render: function (rowdata, rowindex, value){
                        
                    var h='<a class="sq-button-hasicon" href="javascript:sendFile(';
                        h+="'"+rowdata.billId+"'";
                        h+=",'mid_man_grid_id'"
                        h+=")\"><i class=\"sqBtnIco_4\"></i>发送</a>"
                   	var returnStr = h;  
                   	return returnStr;
                }
            }
    	return data;
	}

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }
    
  //定义父级调用事件
	frameElement.dialog.onOk = function () {
		save();
	}
	
	frameElement.dialog.onCancel = function () {
		frameElement.dialog.close();
	}
	
  //新增
	function save(){
		var data = new Array();//获取表单数据
		var fileParams = getUploadResultParams();//获取附件上传的信息
        data["fileParams"] = JSON.stringify(fileParams);
		var grid = liger.get("ligergrid1");
		var selectedRows = grid.getSelectedRows();
		if(selectedRows.length < 1){
			UIUtils.alertError("请至少选择一条数据");
			return;
		}
		var ids = [];
		for(var i=0;i<selectedRows.length;i++){
			var id = selectedRows[i].id;
			ids[i] = id;
		}
		data["ids"] = JSON.stringify(ids);
        var url = '<%=path%>/mcr/mcrBillM/uploadPic.do';
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {ids: JSON.stringify(ids) ,fileParams: JSON.stringify(fileParams)},
            url: url,
            beforeSend: function(){
                wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
            },
            success:function(msg){
                wait_dialog.close();
                if(msg.success == 1){
                    $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                    searchBtn();
                }else{
                    $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
                }
            }
        });
	}
  
	//初始化表单
	function initForm(){
		$("#searchBar").ligerForm();
	}
	
	//查询按钮事件
	function searchBtn(){
        var form = new liger.get("searchBar");
        var data = form.getData();
        for (name in data){
           grid.setParm(name,data[name]);
        };
       grid.reload();
	}
	//清空按钮事件
	function clearBtn(){
		 $("#resetBtn").click();  //重置 input-text
		 var form = new liger.get("searchBar");
		 form.setData({  //重置select等特殊表单
		    "loanId":"",
		    "accountId":""
		  });
	}
	
	//删除数据
  	function sendFile(_id){
  		$.ligerDialog.confirm('确定发送吗?', function (flag) {
			if(flag == false)return;
			var url = '<%=path%>/mcr/mcrBillM/sendFileYNXT.do';
			AjaxUtils.ajaxPost(url, {id:_id}, delCallback);
		});
  	}
	
  	function delCallback(msg){
  		if(msg.success == 1){
			 UIUtils.alertSuccess(msg.info);
			 grid.reload();
		 }else{
			 UIUtils.alertError(msg.info);
		 }
  	}

    //查看数据
    function showDetail(_id){
        parent.mainApp.f_addTab('tab_customer_np_detail'+_id,'客户详情','<%=path%>/customer/cstbscinfo/toCustCstBacInfoNpDetailPage.do?id='+_id);
    }

</script>

</body>
</html>
